#include "toHelix.h"

toHelix::toHelix()
{
}


toHelix::~toHelix()
{
}

void* toHelix::creator()
{
	return new toHelix;
}

MStatus toHelix::doIt(const MArgList& args)
{
	MStatus status;

	MSelectionList selectedObjs;

	MGlobal::getActiveSelectionList(selectedObjs);

	if (selectedObjs.isEmpty(&status))
	{
		MGlobal::displayInfo("selected nothing");
		return status;
	}

	for (unsigned int i = 0; i < selectedObjs.length(); ++i)
	{
		MDagPath selected_obj;
		MDagPath curve_shape;
		MFnNurbsCurve curveFn;
		MObject selected_comp;

		selectedObjs.getDagPath(i, selected_obj, selected_comp);

		selected_obj.extendToShape();

		MString obj_name = selected_obj.partialPathName();
		MGlobal::displayInfo(obj_name + " is selected.");

		if (selected_obj.apiType(&status) != MFn::kNurbsCurve)
		{
			MGlobal::displayError("selected object is not nurbs curve");
			return status;
		}

		curveFn.setObject(selected_obj);

		MPointArray old_cvs;
		MPointArray new_cvs;

		curveFn.getCVs(old_cvs);
		new_cvs = old_cvs;

		for (unsigned int i = 0; i <	new_cvs.length();  i++)
		{
			double x = radius * sin(i);
			double y = i * pitch;
			double z = radius * cos(i);
			MPoint p (x, y, z);
			new_cvs.set(p, i);
		}

		curveFn.setCVs(new_cvs);
		curveFn.updateCurve();
	}

	return status;
}
